<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function quickSort(arr) {
      if (arr.length === 1 || arr.length === 0) return arr;
      let leftArr = [];
      let rightArr = [];
      arr.slice(1).forEach((item) => {
        if (item < arr[0]) {
          leftArr.push(item);
        } else {
          rightArr.push(item);
        }
      });
      leftArr = quickSort(leftArr);
      rightArr = quickSort(rightArr);
      leftArr.push(arr[0]);
      return [...leftArr, ...rightArr];
    }
    const arr = [4, 546, 123, 4, 652, 5, 7, 3, 2, 56]

    console.log(quickSort(arr));
  </script>
</body>

</html>